<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>试卷编辑</title>
    <link rel="shortcut icon" href="/favicon.ico">
    <link href="/public/admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/public/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/public/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/public/admin/css/animate.css" rel="stylesheet">
    <link href="/public/admin/css/style.css?v=4.0.0" rel="stylesheet">
    <link href="/public/admin/js/plugins/layer/skin/layer.css" rel="stylesheet">
    <base target="_blank">
    <link href="/public/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <!-- 全局js -->
    <script src="/public/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/admin/js/bootstrap.min.js?v=3.3.5"></script>
    <script src="/public/admin/js/plugins/layer/layer.min.js"></script>
    <!-- 自定义js -->
    <script src="/public/admin/js/content.js?v=1.0.0"></script>
    <script src="/public/admin/js/contabs.js"></script>
    <script src="/public/admin/js/common.js"></script>
    <script src="/public/admin/js/article.js"></script>

    <!-- Bootstrap table -->
    <script src="/public/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/public/admin/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="/public/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <!-- iCheck -->
    <script src="/public/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="/public/common/my.js"></script>
    <style>
        .modal-header{
            padding:10px 15px 0px 15px;
        }
        .modal-body {
            padding: 0px 30px 0px 30px;
        }
        .pagination{
            margin:5px 0px 0px 0px;
        }
        .table{
            margin-bottom:0px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <!-- <div class="ibox-title">
                    <h5>普通试题管理</h5>
                </div> -->
                <div class="ibox-content">
                    <ul class="nav nav-tabs">
                        <li class="active"><a data-toggle="tab" href="#tab-1"> 基本信息</a></li>
                        <!-- <a href="javascript:history.go(-1)" class="btn btn-primary pull-right"><i class="fa fa-reply"></i>返回</a> -->
                    </ul>
                    <br/>
                    <div class="row">
                        <form action="{:url('Article/articleHandle')}" method="post" id="articleFrom" class="form-horizontal">
                            <div class="tab-content">
                                <div id="tab-1" class="tab-pane active">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">试卷名称：</label>
                                        <div class="col-sm-8">
                                            <input class="configInput form-control" name="exam_name" minlength="2" type="text" value="{$exam.exam_name}" required="" aria-required="true">
                                        </div>
                                    </div>
                                    <div class="form-group" style="display:none">
                                        <label class="col-sm-2 control-label">考试科目：</label>
                                        <div class="col-sm-2">
                                            <select class="form-control" name="subjectid" disabled>
                                                {foreach name="subjectList" item="v"}
                                                <option value="{$v.subjectid}" {eq name="v.subjectid" value="$exam['subjectid']"}selected="selected"{/eq}>{$v.subject_name}</option>
                                                {/foreach}
                                            </select>
                                        </div>
                                    </div>
                                    {php}
                                        $subject = Db::name('subject')->find($exam['subjectid']);
                                    {/php}
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">科目：</label>
                                        <div class="col-sm-8">
                                            <input class="configInput form-control" name="" minlength="2" type="text" value="{$subject.subject_name}" required="" aria-required="true" placeholder="" disabled>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-2">考试时间：</label>
                                        <div class="col-sm-8 form-inline">
                                            <input type="text" name="exam_time" size=8" needle="needle" class="form-control" value="{$exam.exam_time}" autocomplete="off"> 分钟
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">试卷总分：</label>
                                        <div class="col-sm-3">
                                            <input class="configInput form-control" name="exam_score" minlength="2" type="number" value="{$exam.exam_score}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">及格线：</label>
                                        <div class="col-sm-3">
                                            <input class="configInput form-control" name="pass_line" minlength="2" type="number" value="{$exam.pass_line}">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>
                                    <div class="form-group questpanel panel_1">
                                        <label class="control-label col-sm-2">单选题：</label>
                                        <div class="col-sm-9 form-inline">
                                            <span class="info">共&nbsp;</span>
                                            <input type="text" class="form-control q-num" name="" value="{$exam.exam_setting.radio.total_num}" size="1">
                                            <span class="info">&nbsp;题，每题&nbsp;</span><input class="form-control q-score" type="text" name="" value="{$exam.exam_setting.radio.score}" size="1">
                                            <span class="info">&nbsp;分，描述&nbsp;</span><input class="form-control q-desc" type="text" name="" value="{$exam.exam_setting.radio.desc}" size="28">
                                            <span class="info">&nbsp;已选题数：<a class="ialreadyselectnumber">{$exam.exam_setting.radio.select_num}</a>&nbsp;&nbsp;题</span>
                                            <span style="display:none" class="info">&nbsp;<a class="selfmodal btn btn-info" href="javascript:;">看题</a></span>
                                            <span class="selectQuestion" data-qtypeid="1">&nbsp;<a class="selfmodal btn btn-primary" href="javascript:;">选题</a></span>
                                            <input type="hidden" id="iselectquestions_1" name="" value="{$exam.exam_setting.radio.questionids}">
                                        </div>
                                    </div>
                                    <div class="form-group questpanel panel_2">
                                        <label class="control-label col-sm-2">多选题：</label>
                                        <div class="col-sm-9 form-inline">
                                            <span class="info">共&nbsp;</span>
                                            <input type="text" class="form-control q-num" name="" value="{$exam.exam_setting.check.total_num}" size="1">
                                            <span class="info">&nbsp;题，每题&nbsp;</span><input class="form-control q-score" type="text" name="" value="{$exam.exam_setting.check.score}" size="1">
                                            <span class="info">&nbsp;分，描述&nbsp;</span><input class="form-control q-desc" type="text" name="" value="{$exam.exam_setting.check.desc}" size="28">
                                            <span class="info">&nbsp;已选题数：<a class="ialreadyselectnumber">{$exam.exam_setting.check.select_num}</a>&nbsp;&nbsp;题</span>
                                            <span style="display:none" class="info">&nbsp;<a class="selfmodal btn btn-info" href="javascript:;">看题</a></span>
                                            <span class="selectQuestion" data-qtypeid="2">&nbsp;<a class="selfmodal btn btn-primary" href="javascript:;">选题</a></span>
                                            <input type="hidden" id="iselectquestions_2" name="" value="{$exam.exam_setting.check.questionids}">
                                        </div>
                                    </div>
                                    <div class="form-group questpanel panel_3">
                                        <label class="control-label col-sm-2">判断题：</label>
                                        <div class="col-sm-9 form-inline">
                                            <span class="info">共&nbsp;</span>
                                            <input type="text" class="form-control q-num" name="" value="{$exam.exam_setting.judge.total_num}" size="1">
                                            <span class="info">&nbsp;题，每题&nbsp;</span><input class="form-control q-score" type="text" name="" value="{$exam.exam_setting.judge.score}" size="1">
                                            <span class="info">&nbsp;分，描述&nbsp;</span><input class="form-control q-desc" type="text" name="" value="{$exam.exam_setting.judge.desc}" size="28">
                                            <span class="info">&nbsp;已选题数：<a class="ialreadyselectnumber">{$exam.exam_setting.judge.select_num}</a>&nbsp;&nbsp;题</span>
                                            <span style="display:none" class="info">&nbsp;<a class="selfmodal btn btn-info" href="javascript:;">看题</a></span>
                                            <span class="selectQuestion" data-qtypeid="3">&nbsp;<a class="selfmodal btn btn-primary" href="javascript:;">选题</a></span>
                                            <input type="hidden" id="iselectquestions_3" name="" value="{$exam.exam_setting.judge.questionids}">
                                        </div>
                                    </div>
                                    <div class="form-group questpanel panel_4">
                                        <label class="control-label col-sm-2">填空题：</label>
                                        <div class="col-sm-9 form-inline">
                                            <span class="info">共&nbsp;</span>
                                            <input type="text" class="form-control q-num" name="" value="{$exam.exam_setting.fill.total_num}" size="1">
                                            <span class="info">&nbsp;题，每题&nbsp;</span><input class="form-control q-score" type="text" name="" value="{$exam.exam_setting.fill.score}" size="1">
                                            <span class="info">&nbsp;分，描述&nbsp;</span><input class="form-control q-desc" type="text" name="" value="{$exam.exam_setting.fill.desc}" size="28">
                                            <span class="info">&nbsp;已选题数：<a class="ialreadyselectnumber">{$exam.exam_setting.fill.select_num}</a>&nbsp;&nbsp;题</span>
                                            <span style="display:none" class="info">&nbsp;<a class="selfmodal btn btn-info" href="javascript:;">看题</a></span>
                                            <span class="selectQuestion" data-qtypeid="4">&nbsp;<a class="selfmodal btn btn-primary" href="javascript:;">选题</a></span>
                                            <input type="hidden" id="iselectquestions_4" name="" value="{$exam.exam_setting.fill.questionids}">
                                        </div>
                                    </div>
                                    <div class="hr-line-dashed"></div>


                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <input type="hidden" name="examid" value="{$exam.examid}">
                                    <button class="btn btn-primary" type="button" id="examSave">保存</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

                <div id="modal" class="modal fade in" style="display: none; padding-right: 17px;">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button aria-hidden="true" class="close closeSelect" type="button" data-dismiss="modal" autocomplete="off">×</button>
                                <h4 id="myModalLabel">
                                    试题详情
                                </h4>
                            </div>
                            <div class="modal-body" id="modal-body">

                            </div>
                            <div class="modal-footer">
                                <button aria-hidden="true" class="btn btn-primary completeSelect" data-dismiss="modal" autocomplete="off">完成</button>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>
    </div>
</div>


<input id="handle_status" value="" hidden="hidden">
<script>
    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
    });
    $('.selectQuestion').on('click',function(){
        var subjectid = $("select[name='subjectid']").val();
        var qtypeid = $(this).attr('data-qtypeid');
        $.ajax({
            type:'post',
            url:"{:url('Exam/ajaxQuestionSelect')}",
            data:{'subjectid':subjectid,qtypeid:qtypeid},
            success:function(html){
                $("#modal-body").html(html);
                $("#modal").slideDown();
            },
            error:function(){
                layer.msg('请检查当前的网络连接!');
            }
        });
    });
    $(".closeSelect").on('click',function(){
        $("#modal").slideUp();
    });
    //完成事件，处理选中的input
    $(".completeSelect").on("click",function(){
        $("#modal").slideUp();
    });
    function selectQuestion(obj){
        var qtypeid = $("#qtypeid").val();
        var old_select_str = $("#iselectquestions_"+qtypeid+"").val();
        var old_select_arr = old_select_str.split(','); //字符串转数组
        var checkids_arr = [];
        if($(obj).prop('checked')){
            checkids_arr.push($(obj).val());
            var new_check_arr = concat_(old_select_arr,checkids_arr); //合并数组去重

            $(".panel_"+qtypeid+"").find(".ialreadyselectnumber").html((new_check_arr.length-1));
            var new_check_str = new_check_arr.join(','); //数组转字符串
            $("#iselectquestions_"+qtypeid+"").val(new_check_str);
        }else{
            if(isInArray($(obj).val(),old_select_arr)){
                removeByValue(old_select_arr,$(obj).val());
            }
            var new_check_arr = old_select_arr;

            $(".panel_"+qtypeid+"").find(".ialreadyselectnumber").html((new_check_arr.length-1));
            var new_check_str = new_check_arr.join(','); //数组转字符串
            $("#iselectquestions_"+qtypeid+"").val(new_check_str);
        }
    }
    function selectQuestionCompelete(){
        var qtypeid = $("#qtypeid").val();
        var old_select_str = $("#iselectquestions_"+qtypeid+"").val();
        var old_select_arr = old_select_str.split(','); //字符串转数组
        var checkidsAll = [];
        var checkids_arr = [];
        //先去除当前页的值
        $("#ajaxList table tr td .sbox").each(function(i){
            checkidsAll.push($(this).val());
        });
        for(var n in checkidsAll){
            if(isInArray(checkidsAll[n],old_select_arr)){
                removeByValue(old_select_arr,checkidsAll[n]);
            }
        }
        //然后整合选中的值
        $("#ajaxList table tr td .sbox:checked").each(function(i){
            checkids_arr.push($(this).val());
        });
        var new_check_arr = concat_(old_select_arr,checkids_arr); //合并数组去重
        console.log(new_check_arr);
        $(".panel_"+qtypeid+"").find(".ialreadyselectnumber").html((new_check_arr.length-1));
        var new_check_str = new_check_arr.join(','); //数组转字符串
        $("#iselectquestions_"+qtypeid+"").val(new_check_str);
    }

    $("#examSave").on("click",function(event){
        event.preventDefault();
        var data = {
            examid : $("input[name='examid']").val(),
            exam_name : $("input[name='exam_name']").val(),
            subjectid : $("select[name='subjectid']").val(),
            exam_time : $("input[name='exam_time']").val(),
            exam_score : $("input[name='exam_score']").val(),
            pass_line : $("input[name='pass_line']").val(),
            question_info : {
                radio : {
                    total_num : $(".panel_1 .q-num").val(),
                    score : $(".panel_1 .q-score").val(),
                    desc : $(".panel_1 .q-desc").val(),
                    select_num : $(".panel_1").find(".ialreadyselectnumber").html(),
                    questionids : $("#iselectquestions_1").val()
                },
                check : {
                    total_num : $(".panel_2 .q-num").val(),
                    score : $(".panel_2 .q-score").val(),
                    desc : $(".panel_2 .q-desc").val(),
                    select_num : $(".panel_2").find(".ialreadyselectnumber").html(),
                    questionids : $("#iselectquestions_2").val()
                },
                judge : {
                    total_num : $(".panel_3 .q-num").val(),
                    score : $(".panel_3 .q-score").val(),
                    desc : $(".panel_3 .q-desc").val(),
                    select_num : $(".panel_3").find(".ialreadyselectnumber").html(),
                    questionids : $("#iselectquestions_3").val()
                },
                fill : {
                    total_num : $(".panel_4 .q-num").val(),
                    score : $(".panel_4 .q-score").val(),
                    desc : $(".panel_4 .q-desc").val(),
                    select_num : $(".panel_4").find(".ialreadyselectnumber").html(),
                    questionids : $("#iselectquestions_4").val()
                }
            }
        };
        console.log(data);
        //doAjax(data,"/Admin/Exam/examEdit.html",'post',callback);
        ajax_submit("/Admin/Exam/examEdit.html",data);
    });
    function callback(res){
        if(res.status == 1){
            layer.msg(res.msg,{time:1000},function(){
//                $("#modal").slideUp();
                window.location = "/index.php/Admin/Exam/index"
            })
        }else{
            layer.msg(res.msg);
        }
    }


</script>

</body>

</html>